<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <!-- [EasyUI] -->
<link id="easyuiTheme" rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.1/themes/gray/easyui.css" />
<link id="easyuiTheme" rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.1/themes/icon.css" />
<script type="text/javascript" src="/static/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/static/js/HhUtil.js?t=20170109"></script>

    <!-- [扩展样式] -->
    <link rel="stylesheet" type="text/css" href="/static/css/dreamlu.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/icommon.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/login.css" />
    <link rel="stylesheet" type="text/css" href="../aui/css/aui.css" />
    <script type="text/javascript" src="/static/js/template-web.js"></script>
</head>
<body>
<table>

    <td><a href="javascript:addFun()" class="user-easyui-linkbutton-add" data-options="plain:true,iconCls:'icon-add'"></a></td>
    </table>
</body>
<div id="main"></div>

</body>

<script id="ad_info" type="text/html">
    {{each info as item i}}
    <div class="aui-content aui-margin-b-15">
    <ul class="aui-list aui-media-list">
        <li class="aui-list-item">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-media" style="width:40%;">
                    <img src="{{item.title_url}}" style="height: 80px">
                </div>
                <div class="aui-list-item-inner">
                    <div class="aui-info-item"><span>发布时间： {{item.pubtime}}</span>&nbsp&nbsp&nbsp&nbsp<span>标题： {{item.title}}</span></div>
                    {{ if item.type == '0' }}
                    <div class="aui-info-item">类型： 编辑内容</div>
                    {{/if}}
                    {{ if item.type == '1' }}
                    <div class="aui-info-item">类型： H5页面</div>
                    {{/if}}
                    {{ if item.type == '2' }}
                    <div class="aui-info-item">类型： 原生页面</div>
                    {{/if}}
                    <div class="aui-list-item-text">
                        <form id="ad_form{{item.ad_id}}" method="post" action="/saveadtype">
                        <input type="hidden" name="ad_id" value="{{item.ad_id}}">
                        {{ if item.circle == 1 }}
                            <input type="checkbox" name="ad_type" value="0" checked="checked">考友圈
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="0">考友圈
                        {{/if}}

                        {{ if item.one == 1 }}
                            <input type="checkbox" name="ad_type" value="1" checked="checked">科目一
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="1">科目一
                        {{/if}}

                        {{ if item.two == 1 }}
                            <input type="checkbox" name="ad_type" value="2" checked="checked">科目二
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="2">科目二
                        {{/if}}

                        {{ if item.three == 1 }}
                            <input type="checkbox" name="ad_type" value="3" checked="checked">科目三
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="3">科目三
                        {{/if}}

                        {{ if item.four == 1 }}
                            <input type="checkbox" name="ad_type" value="4" checked="checked">科目四
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="4">科目四
                        {{/if}}

                        {{ if item.vip == 1 }}
                            <input type="checkbox" name="ad_type" value="5" checked="checked">VIP
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="5">VIP
                        {{/if}}

                        {{ if item.index == 1 }}
                            <input type="checkbox" name="ad_type" value="6" checked="checked">默认首页
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="6">默认首页
                        {{/if}}

                        {{ if item.couch_index == 1 }}
                            <input type="checkbox" name="ad_type" value="7" checked="checked">教练首页
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="7">教练首页
                        {{/if}}

                        {{ if item.student_index == 1 }}
                            <input type="checkbox" name="ad_type" value="8" checked="checked">学员首页
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="8">学员首页
                        {{/if}}

                        {{ if item.couch_circle == 1 }}
                            <input type="checkbox" name="ad_type" value="9" checked="checked">教练圈
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="9">教练圈
                        {{/if}}

                        {{ if item.pub_consult == 1 }}
                            <input type="checkbox" name="ad_type" value="10" checked="checked">一键咨询
                        {{ else}}
                            <input type="checkbox" name="ad_type" value="10">一键咨询
                        {{/if}}


                        <a href="javascript:saveFun({{item.ad_id}})" class="user-easyui-linkbutton-save" data-options="plain:true,iconCls:'icon-save'"></a>
                        </form>
                    </div>
                    <div>
                        <a href="javascript:editFun({{item.ad_id}},{{item.type}})" class="user-easyui-linkbutton-edit" data-options="plain:true,iconCls:'icon-del'"></a>
                        <a href="javascript:delFun({{item.ad_id}})" class="user-easyui-linkbutton-del" data-options="plain:true,iconCls:'icon-del'"></a>
                    </div>
                </div>
            </div>
        </li>
    </ul>
</div>
{{/each}}
</script>

<script type="text/javascript">


    function addFun() {
        location.href="ad_add.html"
    }

    function editFun(ad_id,t) {
        location.href="/static/ad/ad_detail.html?ad_id=" + ad_id
    }


    function delFun(ad_id) {
        $.messager.confirm(HdUtil.constant.CONFIRM, HdUtil.constant.DELETE_CONFIRM, function (r) {
            if (r) {
                $.ajax({
                    method: "post",
                    url: "/delad",
                    data: {
                        ad_id: ad_id
                    },
                    success: function (data) {
                        if (data.code == "0") {
                            HdUtil.messager.slide(HdUtil.constant.DELETE_SUCCESS);
                            location.href="/static/ad/ad_list.html"
                        } else {
                            HdUtil.messager.error(data.msg);
                        }
                    }
                })
            }
        });
    }

    function saveFun(ad_id) {

        $('#ad_form'+ad_id).form("submit", {
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "0") {
                    HdUtil.messager.slide("修改成功");
                } else {
                    HdUtil.messager.error("修改失败");
                }
            }
        });
    }

    $.ajax( {
        url:'/adlist',// 跳转到 action
        type:'get',
        cache:false,
        dataType:'json',
        success:function(data) {
            if(data.code =="0" ){
                var html = template('ad_info',data);
                $("#main").html("").html(html);
                $('.user-easyui-linkbutton-edit').linkbutton({text: '编辑', plain: true, iconCls: 'icon-edit'});
                $('.user-easyui-linkbutton-del').linkbutton({text: '删除', plain: true, iconCls: 'icon-del'});
                $('.user-easyui-linkbutton-save').linkbutton({text: '保存', plain: true, iconCls: 'icon-save'});
                $('.user-easyui-linkbutton-add').linkbutton({text: '添加', plain: true, iconCls: 'icon-add'});
            }else{
                view(data.msg);
            }
         },
         error : function() {
              // view("异常！");
              alert("异常！");
         }
    });
</script>
</html>